package com.ts.login.control;

import com.ts.comm.SysResult;
import com.ts.login.bean.UserInfo;
import com.ts.login.dao.IndexDao;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

/**
 * 首页数据加载
 * Created by xhc on 2017/4/5.
 */
@Controller
public class IndexControl {

    @Resource
    private IndexDao indexDao;

    @RequestMapping(value = "/index",method = RequestMethod.POST)
    @ResponseBody
    public SysResult getMenus(HttpServletRequest req){

        HttpSession session = req.getSession();
        UserInfo userInfo= (UserInfo) session.getAttribute("user");
        SysResult sr=new SysResult();
        try {
            List<Map<String, Object>> menus = indexDao.getMenus(userInfo);
            sr.setRows(menus);
        } catch (Exception e) {
            sr.onSetErrorMsg(e);
        }
        return sr;
    }
}
